package com.yuxin.tongyi.lsll.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yuxin.tongyi.lsll.pojo.Month;
import com.yuxin.tongyi.lsll.pojo.PlanInfo;
import com.yuxin.tongyi.lsll.pojo.Semester;
import com.yuxin.tongyi.lsll.pojo.SumupInfo;
import com.yuxin.tongyi.lsll.pojo.Week;

/**
 * 用于处理请求解析的对象
 * @author zlh
 * @version 1.0
 */
public class EducationPlanUtil {
   
    private Map<Semester,List<Week>> weekmap = new HashMap<Semester,List<Week>>();
    private Map<Semester,List<Month>> monthmap = new HashMap<Semester,List<Month>>();
    private Semester[] semester;
    private Month[] month;
    private Month[][] monthinfo;
    private Week[] week;
    private Week[][] weekinfo;
    private PlanInfo weekPlan;
    private PlanInfo monthPlan;
    private PlanInfo semesterPlan;
    private SumupInfo weekSumUp;
    private SumupInfo monthSumUp;
    private SumupInfo semesterSumUp;
	
	/**
	 * 处理方法
	 */
	public void dealPlanXmlParse(List<Object> objects,int tab) {
		int size = objects.size();
		semester = new Semester[size];
		weekinfo = new Week[size][];
		monthinfo = new Month[size][];
		for (int i=0;i<size;i++) {
			Object obj = objects.get(i);
			if (obj instanceof Semester) {
				semester[i] = (Semester)obj;
				Semester semester = (Semester) obj;
				List<Month> months = semester.getMonth();
			    List<Week> weeks = semester.getWeek();
			    List<PlanInfo> semesterPlans = semester.getPlanInfo();
			    if(months!=null&&months.size()>0) { //周计划相应
			    	 int monthsize = months.size();
			    	 monthinfo[i] = new Month[monthsize];
			    	 month = new Month[monthsize];
			    	 for(int j=0;j<monthsize;j++) {
			    		 Month monthobj = months.get(j);
			    		 List<PlanInfo> infos = monthobj.getPlanInfo(); //月计划
			    		 List<SumupInfo> sumUpinfos = monthobj.getSumUpInfo(); //月总结
			    		 if(infos!=null&&infos.size()>0) {
			    			 monthPlan = infos.get(0);   //月计划
			    			 monthPlan.setSemesterId(String.valueOf(String.valueOf(i)));
			    			 monthPlan.setMonthId(String.valueOf(j));
				    	 }
			    		 if(sumUpinfos!=null&&sumUpinfos.size()>0) {
			    			 monthSumUp = sumUpinfos.get(0);   //月计划
			    			 monthSumUp.setSemesterId(String.valueOf(String.valueOf(i)));
			    			 monthSumUp.setMonthId(String.valueOf(j));
				    	 }
                         month[j] = monthobj;
			    		 monthinfo[i][j] = monthobj;
			    	 }
			    }
			    if(weeks!=null&&weeks.size()>0) { //月计划相应
			    	int weeksize = weeks.size();
			    	weekinfo[i] = new Week[weeksize];
			    	week = new Week[weeksize];
			    	for(int j=0;j<weeks.size();j++) {
			    		Week weekobj = weeks.get(j);
			    	    List<PlanInfo> infos = weekobj.getPlanInfo(); //周计划
			    	    List<SumupInfo> sumUpInfos = weekobj.getSumUpInfo(); //周总结
			    	    if(infos!=null&&infos.size()>0) {
			    	    	weekPlan = infos.get(0);   //周计划
			    	    	weekPlan.setSemesterId(String.valueOf(String.valueOf(i)));
			    	    	weekPlan.setWeekId(String.valueOf(j));
			    	    }
			    	    if(sumUpInfos!=null&&sumUpInfos.size()>0) {
			    	    	weekSumUp = sumUpInfos.get(0);   //周计划
			    	    	weekSumUp.setSemesterId(String.valueOf(String.valueOf(i)));
			    	    	weekSumUp.setWeekId(String.valueOf(j));
			    	    }
			    	    week[j] = weekobj;
			    		weekinfo[i][j] = (Week)weeks.get(j);
			    	}
			    }
			    if(semesterPlans!=null&&semesterPlans.size()>0) {
			    	semesterPlan = semesterPlans.get(0);
			    	semesterPlan.setSemesterId(String.valueOf(String.valueOf(i)));
			    }
			} 
			if(obj instanceof PlanInfo) {
				if(tab==1) {
					weekPlan = (PlanInfo)obj;
				}else if(tab==2) {
					monthPlan = (PlanInfo)obj;
				}else if(tab==3) {
					semesterPlan = (PlanInfo)obj;
				}
			}
			if(obj instanceof SumupInfo) {
				if(tab==1) {
					weekSumUp = (SumupInfo)obj;
				}else if(tab==2) {
					monthSumUp = (SumupInfo)obj;
				}else if(tab==3) {
					semesterSumUp = (SumupInfo)obj;
				}
			}
		}
	}

	public Map<Semester, List<Week>> getWeekmap() {
		return weekmap;
	}

	public Map<Semester, List<Month>> getMontmap() {
		return monthmap;
	}


	public Map<Semester, List<Month>> getMonthmap() {
		return monthmap;
	}

	public Semester[] getSemester() {
		return semester;
	}

	public Month[] getMonth() {
		return month;
	}

	public Month[][] getMonthinfo() {
		return monthinfo;
	}

	public Week[] getWeek() {
		return week;
	}

	public Week[][] getWeekinfo() {
		return weekinfo;
	}

	public PlanInfo getMonthPlan() {
		return monthPlan;
	}

	public PlanInfo getWeekPlan() {
		return weekPlan;
	}

	public PlanInfo getSemesterPlan() {
		return semesterPlan;
	}

	public SumupInfo getWeekSumUp() {
		return weekSumUp;
	}

	public SumupInfo getMonthSumUp() {
		return monthSumUp;
	}

	public SumupInfo getSemesterSumUp() {
		return semesterSumUp;
	}
}
